package com.csj.mvvmtest.ui.first

import androidx.lifecycle.MutableLiveData
import com.csj.mvvm.bean.HttpResponse
import com.csj.mvvm.ui.base.BaseViewModel
import com.csj.mvvmtest.bean.ArticleBean
import com.csj.mvvmtest.bean.FirstBean

class MainViewModel : BaseViewModel() {

    var list = ArrayList<ArticleBean>()

    var articlesData = MutableLiveData<FirstBean>()

    fun getArticleList(page: Int, isShowLoading: Boolean) {
        apiIndex = 1
        get(
            "article/listproject/$page/json",
            liveData = articlesData,
            isShowLoading = isShowLoading
        )
    }

    fun login(username: String, password: String) {
        apiIndex = 2
        val has = mutableMapOf("username" to username, "password" to password)
        postForm<HttpResponse>("user/login", has)
    }

    fun collect(page: Int) {
        apiIndex = 3
        post<HttpResponse>("lg/collect/$page/json")
    }

    fun logout() {
        apiIndex = 4
        get<HttpResponse>("user/logout/json")
    }
}